/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.dao;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.thinkgem.jeesite.common.persistence.BaseDao;
import com.thinkgem.jeesite.common.persistence.BaseDaoImpl;
import com.boxin.ims.modules.wechat.entity.UserBusiness;

/**
 * 用户业务服务定义类DAO接口
 * @author Jakemanse
 * @version 2013-09-27
 */
public interface UserBusinessDao extends UserBusinessDaoCustom, CrudRepository<UserBusiness, Long> {

	@Modifying
	@Query("update UserBusiness set delFlag='" + UserBusiness.DEL_FLAG_DELETE + "' where id = ?1")
	public int deleteById(Long id);
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-24  上午11:35:36
	 * @function <p> 失效 </p>
	 * @param userId
	 * @param configId
	 * @return
	 */
	@Modifying
	@Query("update UserBusiness set delFlag='" + UserBusiness.DEL_FLAG_DELETE + "' where user.id=?1 and  businessConfig.id = ?2")
	public int invalidByUserIdAndConfigId(Long userId,Long configId);
	
	
	@Modifying
	@Query("update UserBusiness set delFlag='" + UserBusiness.DEL_FLAG_DELETE + "' where user.id=?1 ")
	public int invalidAllByUserId(Long userId);
	
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-24  上午11:35:29
	 * @function <p> 生效 </p>
	 * @param userId
	 * @param configId
	 * @return
	 */
	@Modifying
	@Query("update UserBusiness set delFlag='" + UserBusiness.DEL_FLAG_NORMAL + "' where user.id=?1 and  businessConfig.id = ?2")
	public int validByUserIdAndConfigId(Long userId,Long configId);
	
}

/**
 * DAO自定义接口
 * @author Jakemanse
 */
interface UserBusinessDaoCustom extends BaseDao<UserBusiness> {

}

/**
 * DAO自定义接口实现
 * @author Jakemanse
 */
@Component
class UserBusinessDaoImpl extends BaseDaoImpl<UserBusiness> implements UserBusinessDaoCustom {

}
